<template>
  <el-dialog
    :title="addStatus ? '添加动态参数' : '添加静态参数'"
    :visible.sync="dialogVisible"
    width="750px"
    @close='closeDialog'
  >
    <el-form ref="form" :rules="rules" :model="paramData" label-width="80px">
      <el-form-item
        prop="attr_name"
        :label="addStatus ? '动态参数' : '静态参数'"
      >
        <el-input v-model="paramData.attr_name"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="changeParams">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { UserInfoRules } from '@/common/mixin'
import { addParamsApi } from '@/Utils/Api/gitGoodsInfoApi'
export default {
  name: 'addParamsDialog',
  mixins: [UserInfoRules],
  data () {
    return {
      addStatus: true,
      dialogVisible: false,
      paramData: {
        attr_name: ''
      },
      cateId: Number,
      activeName: ''
    }
  },
  components: {},
  created () {},
  mounted () {},
  methods: {
    async changeParams () {
      this.$refs.form.validate(async (vail) => {
        if (!vail) return
        const { data } = await addParamsApi(this.cateId, {
          attr_name: this.paramData.attr_name,
          attr_sel: this.activeName
        })
        console.log(data)
        if (data.meta.status !== 201) {
          return this.$message({
            type: 'error',
            message: data.meta.msg
          })
        }
        this.$emit('getParams')
        this.$message({
          type: 'success',
          message: data.meta.msg
        })
        this.dialogVisible = false
      }
      )
    },
    closeDialog () {
      this.paramData.attr_name = ''
    }
  },
  computed: {},
  watch: {}
}
</script>

<style scoped>
</style>
